import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;

import view.DestinoDTO;
import view.ProveedorDTO;

import com.google.gson.Gson;

import org.json.simple.parser.*;

import controller.Sistema;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Proveedores extends HttpServlet  {
 
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		System.out.println("vaaa Proveedores GET");
		this.ejecutar(req, resp);	
	}


	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException 
	 {
		System.out.println("vaaa Proveedores POST");
		this.ejecutar(req, resp);	
	 }

	private void ejecutar(HttpServletRequest req, HttpServletResponse resp) throws IOException
	{
		System.out.println("vaaa plomooo Proveedores");
		resp.setContentType("application/json");
		Gson gson = new Gson();
		ArrayList<ProveedorDTO> proveedores = Sistema.getInstancia().buscarProveedores();
		
		PrintWriter out = resp.getWriter();	   
		out.print(gson.toJson(proveedores)); 		   
		out.flush();
		out.close();	
	}

}